<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>找回密码-资源基地</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
    <link th:href="@{'/static/images/favicon.ico'}" rel="shortcut icon" type="image/x-icon"/>
    <link rel="stylesheet" type="text/css" th:href="@{'/static/css/register/basic.css'}">
    <link rel="stylesheet" type="text/css" th:href="@{'/static/css/register/eyoucms.css'}">
    <link rel="stylesheet" type="text/css" th:href="@{'/static/css/register/define.css'}">

</head>
<body class="reg retrieve" style="">
<div class="register_index ey-member">
    <div class="container">
        <form name="theForm" id="theForm" class="form-register panel-body fv-form">
            <div class="mip-reg-logo"><a href="/" class="ey-logo"><img
                    src="/static/images/logo.png"></a></div>
            <div class="mip-reg-heading">找回密码</div>
            <div class="form-group group_z">
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-envelope-o"></i></span>
                    <input type="text" name="email" id="email" class="form-control" placeholder="邮箱地址">
                </div>
            </div>
            <div class="form-group group_z">
                <div class="input-group btn-direction">
                    <span class="input-group-addon"><i class="fa fa-shield"></i></span>
                    <div class="formText">
                        <input type="text" class="form-control" id="email_code" name="email_code" placeholder="邮箱验证码">
                    </div>
                    <input type="button" id="email_code_button" onclick="send_email();" class="btn btn-primary sento"
                           value="点击发送">
                </div>
            </div>
            <button class="btn btn-lg btn-primary btn-block group_z" style="width: 100%;" onclick="check_submit();"
                    type="button">下一步
            </button>
            <div class="login_link"><a class="login_link_register" href="/to/login.html">返回登录</a>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript" src="/static/js/jquery-2.2.4.min.js"></script>
<script type="text/javascript" src="/static/layer/layer.js"></script>
<link rel="stylesheet" href="/static/layer/theme/default/layer.css" id="layuicss-layer">
<script type="text/javascript" src="/static/js/common.js"></script>
<script type="text/javascript">
    $(document).keydown(function (event) {
        if (event.keyCode == 13) {
            check_submit();
        }
    });

    function check_submit() {
        var email = $('#email').val();
        var reg = /^[a-z0-9]([a-z0-9\\.]*[-_]{0,4}?[a-z0-9-_\\.]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+([\.][\w_-]+){1,5}$/i;
        // 邮箱格式不正确
        if (!reg.test(email)) {
            layer.msg('邮箱格式不正确，请正确输入邮箱地址！', {time: 1500});
            return false;
        }
        var email_code = $('#email_code').val();
        if (email_code == '') {
            layer.msg('邮箱验证码不能为空', {time: 1000});
            return false;
        }
        layer_loading('正在处理');
        $.ajax({
            url: "/veryEmail.html",
            data: {
                "emailCode": email_code,
                "userEmail": email
            },
            type: 'post',
            success: function (res) {
                layer.closeAll();
                if (res.rt == 500) {
                    showErrorMsg("网络出现异常,请稍后重试!");
                    return;
                }
                //有问题
                if (res.code == 1) {
                    window.location.href = res.url;
                } else {
                    layer.msg(res.msg, {time: 2000, icon: 5});
                }
            },
            error: function (e) {
                layer.closeAll();
                showErrorMsg("网络出现异常,请稍后重试!");
            }
        });
    };

    function send_email() {
        var email = $('#email').val();
        var reg = /^[a-z0-9]([a-z0-9\\.]*[-_]{0,4}?[a-z0-9-_\\.]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+([\.][\w_-]+){1,5}$/i;
        // 邮箱格式不正确
        if (!reg.test(email)) {
            layer.msg('邮箱格式不正确，请正确输入邮箱地址！', {time: 1500});
            return false;
        }
        $("#email_code_button").val('发送中…');
        $("#email_code_button").attr('disabled', 'disabled');
        layer_loading('正在处理');
        $.ajax({
            url: "/res-login/sendEmail.html",
            data: {email: email, title: '找回密码', type: 2},
            type: 'get',
            success: function (res) {
                layer.closeAll();
                if (res.rt == -1) {
                    $("#email_code_button").val('点击发送');
                    $("#email_code_button").removeAttr("disabled");
                    showErrorAlert('参数有误');
                    return;
                }
                if (res.rt == -2) {
                    $("#email_code_button").val('点击发送');
                    $("#email_code_button").removeAttr("disabled");
                    showErrorAlert('邮箱已被注册');
                    return;
                }
                if (res.rt == -3) {
                    $("#email_code_button").val('点击发送');
                    $("#email_code_button").removeAttr("disabled");
                    showErrorAlert('邮箱不存在');
                    return;
                }
                if (res.rt == 500) {
                    showErrorMsg("网络出现异常,请稍后重试!");
                    return;
                }
                if (res.rt == 1) {
                    layer.msg("发送成功", {icon: 6});
                    countdown();
                }
            },
            error: function (e) {
                layer.closeAll();
                $("#email_code_button").val('点击发送');
                $("#email_code_button").removeAttr("disabled");
                showErrorAlert("网络异常,请稍后再试!");
            }
        });
    };

    function countdown() {
        // 倒计时
        var setTime;
        var time = 120;
        setTime = setInterval(function () {
            if (0 >= time) {
                clearInterval(setTime);
                return;
            }
            time--;
            $("#email_code_button").val(time + '秒');
            $("#email_code_button").attr('disabled', 'disabled');

            if (time == 0) {
                $("#email_code_button").val('点击发送');
                $("#email_code_button").removeAttr("disabled");
            }
        }, 1000);
    }
</script>


</body>
</html>
